package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:char(11)"`
	Password string `gorm:"type:varchar(32)"`
	HeadImg  string `gorm:"type:varchar(200)"`
	Status   int64  `gorm:"type:int;default:1;comment:状态:1 正常 0 禁用"`
}
type UserRealname struct {
	gorm.Model
	UserId   int64  `gorm:"type:int(10)"`
	Realname string `gorm:"type:varchar(30)"`
	Idcard   string `gorm:"type:varchar(18)"`
}

func (u *User) Create() error {
	return DB.Create(&u).Error
}
func (u *User) FindUserByMobile() error {
	return DB.Where("mobile = ?", u.Mobile).Limit(1).Find(&u).Error
}
func (u *User) Update() error {
	return DB.Model(u).Updates(&u).Error
}
func (u *User) UserList() (userList []*User, err error) {
	err = DB.Model(u).Where("status = 1").Find(&userList).Error
	return
}
func (ur *UserRealname) Create() error {
	return DB.Create(&ur).Error
}
func (ur *UserRealname) FindRealnameByUserId() error {
	return DB.Where("user_id = ?", ur.UserId).Limit(1).Find(&ur).Error

}
